//
//  BJSettingViewController.m
//  BowJoy
//
//  Created by  on 2024/5/14.
//

#import "BJSettingViewController.h"
#import "AppDelegate.h"
#import "BJDeleteAccountView.h"
#import "BJWebContentViewController.h"

@interface BJSettingViewController ()
@property (weak, nonatomic) IBOutlet UIView *bgGroundView;
@property (weak, nonatomic) IBOutlet UILabel *idLable;
@property (weak, nonatomic) IBOutlet UISwitch *autoSwitch;

@end

@implementation BJSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.naviTitle = @"Setting";

    
    self.idLable.text = [BJUserManager sharedManager].userInfoData.userId;

    // Do any additional setup after loading the view from its nib.
}

- (IBAction)clickSwitchBtn:(UISwitch *)sender {
    
}


- (IBAction)clickOutLoginBtn:(id)sender {
    kWeakSelf(weakSelf)

    [[BJNetManager shareNetManager]postSecurityLogoutWithCompletionHandler:^(id  _Nonnull responOj, NSError * _Nonnull error){
        if(!error){
            NSMutableArray *dataList = [NSMutableArray array];
            NSDictionary *dict = @{
                @"page":@"logout",
                @"duration":@(0),
                @"event":@"pv",
                @"tm":@([[BJNetManager shareNetManager] gs_getCurrentTimeToMilliSecond]),
            };
            [dataList addObject:dict];
            [[BJNetManager shareNetManager]postLogWithParam:dataList];
            [weakSelf logout];
        }else{
            [ASHUD showWithText:@"error" afterDelay:1];
        }
    }];

}

- (IBAction)clickDeleteUserBtn:(id)sender {

    BJDeleteAccountView *deleteView = [[BJDeleteAccountView alloc]initWithFrame:self.view.frame];
    self.view.addChild(deleteView);
    deleteView.confirmLabel.onClick((^{
        [ASHUD showASLoading];
        [[BJNetManager shareNetManager] postDeleteAccountWithCompletionHandler:^(id _Nonnull responseObj,NSError * _Nonnull error){
            [ASHUD hideHUD];
            NSDictionary *dict = responseObj;
            NSInteger code = [dict[@"code"] integerValue];
            if (!error && code == 0){
                //                NSLog(@"清空缓存");
                [[BJFMDBManager sharedManager] deleteData];
                [[BJPushFMDBManger sharedManager] deleteData];
                [[BJFMDBVoiceManager sharedManager] deleteData];                
                [[BJFMDBCommentManager sharedManager] deleteData];
                [[BJFMDBBlockManager sharedManager]deleteData];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:kTodayDateKey];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:KCheckNumKey];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:KIsAvatarFrameKey];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:KSelectPictureFrameKey];
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:KCheckAllNumKey];
                [BJUserManager sharedManager].followingNum = 0;
                [BJUserManager sharedManager].blockNum = 0;

                [kAppDelegate setRootViewControllerForLoginVc];
                NSMutableArray *dataList = [NSMutableArray array];
                NSDictionary *dict = @{
                    @"page":@"deleteaccount",
                    @"duration":@(0),
                    @"event":@"pv",
                    @"tm":@([[BJNetManager shareNetManager] gs_getCurrentTimeToMilliSecond]),
                };
                [dataList addObject:dict];
                [[BJNetManager shareNetManager]postLogWithParam:dataList];
                
            }else{
                [ASHUD showWithText:@"error" afterDelay:1];
            }
        }];
        
    }));

}

-(void)logout{
    [kAppDelegate setRootViewControllerForLoginVc];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
